<template>
  <el-form label-width="110px" :model="form" size="small" :disabled="show !== 5">
    <el-col :xl="8" :lg="12" :md="12" :sm="24" :xs="24">
      <el-form-item label="公众号APPID：">
        <el-input class="w240" v-model="form.weixin_appid"></el-input>
      </el-form-item>
    </el-col>
    <el-col :xl="16" :lg="12" :md="12" :sm="24" :xs="24">
      <el-form-item label="公众号SECRET：">
        <el-input class="w240" v-model="form.weixin_secret"></el-input>
      </el-form-item>
    </el-col>
    <el-col :span="24">
      <el-form-item>
        <el-button type="primary" size="small" @click="handleClickSubmit" :loading="loading" :disabled="disabled">保存信息</el-button>
      </el-form-item>
    </el-col>
  </el-form>
</template>

<script>
import { mapGetters } from 'vuex'
import { merchantWechatUpdate } from '@/api/shop'

export default {
  data() {
    return {
      loading: false,
      disabled: false,
      form: {
        weixin_secret: '',
        weixin_appid: ''
      }
    }
  },
  computed: {
    ...mapGetters([
      'id'
    ])
  },
  props: {
    merchantNum: {
      required: true
    },
    show: {
      required: true,
      type: Number
    }
  },
  methods: {
    handleClickSubmit() {
      this.loading = true
      merchantWechatUpdate(this.merchantNum, this.id, this.form).then(res => {
        if (res.data.errorCode === 0) {
          this.$message.success('微信公众号资料提交成功~')
          this.loading = false
          this.disabled = true
          this.$router.go(-1)
        } else {
          this.$message.error(res.data.errorMsg)
        }
      })
    }
  }
}
</script>